package com.guyu.plugin.mybatis.entity;

import com.guyu.common.core.enums.DeletedEnum;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class BaseDO {

    /**
     * 创建时间
     */
    protected LocalDateTime createTime;
    /**
     * 更新时间
     */
    protected LocalDateTime updateTime;
    /**
     * 删除字段
     *
     * @see com.guyu.common.core.enums.DeletedEnum
     */
    protected Long deleted;

    /**
     * 初始化
     */
    public void init() {
        init(LocalDateTime.now());
    }

    /**
     * 初始化
     *
     * @param date 当前时间
     */
    public void init(LocalDateTime date) {
        this.deleted = DeletedEnum.NORMAL.getCode();
        this.createTime = date;
        this.updateTime = date;
    }


    /**
     * 是否删除
     */
    public Boolean hasDeleted() {
        return DeletedEnum.isDeleted(this.deleted);
    }

}
